package day_2022_7_to_8.day48;

/**
 * @author haomin
 * @date 2022/08/14 18:10
 **/
public class Day29_3_Num38_CountAndSay {
    public static void main(String[] args) {
        System.out.println(countAndSay(3));
    }
        public static String countAndSay(int n) {
            String str = "1";
            for(int i = 1;i < n;i++){
                StringBuffer sb = new StringBuffer();
                for (int l = 0, r = 0; r < str.length(); ) {
                    while (r < str.length() && str.charAt(r) == str.charAt(l)) r++;
                    sb.append(r - l).append(str.charAt(l));
                    l = r;
                }
                str = sb.toString();
            }
            return str.toString();
        }

}